<!doctype html>
<html>
<head>
    <!--Setting-->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="apple-mobile-web-app-capable"  content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no">
    
    
    <!--Simple SEO-->


<meta name="robots" content=all />
<meta name="google" content=all />
<meta name="googlebot" content=all />
<meta name="verify" content=all />
    <!--Title-->

<title>git_mark | MIAbon&#39;s blog</title>

<link rel="alternate" href="/atom.xml" title="MIAbon&#39;s blog" type="application/atom+xml">


<link rel="icon" href="/favicon.ico">

    
<link rel="stylesheet" href="/css/base.css">
<link rel="stylesheet" href="/css/pages/post.css">
<link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/thirdParty/highlight/github.css">
<link rel="stylesheet" href="/.css">

    <!--script-->


<script src="http://cdn1.lncld.net/static/js/3.2.1/av-min.js"></script>
<script>
  var appId = "i7AHmC7NPbPtgS3YxT67dRIc-9Nh9j0Va";
  var appKey = "g6TKbY8O4TsCDMcemoC3STvQ";
  var region = "";
  AV.init({
    appId: appId,
    appKey: appKey,
    region: region
  });
</script>


<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<!--<script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>-->


    
    
</head>

<body id="normal">
<!--[if lte IE 8]>
<style>
    html{ font-size: 1em }
</style>
<![endif]-->
<!--[if lte IE 9]>
<style>
    header{ top: 71px; position: absolute!important;}
    #container{padding-top: 151px!important;}
</style>
<div style="position:fixed;z-index:9999;left:0;top:0;width:100%;height:70px;background-color:#e0e0e0;color:#396CA5;border-bottom:1px solid #cecece;text-align:center;line-height:70px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis">你使用的浏览器版本过低，为了你更好的阅读体验，请更新浏览器的版本或者使用其他现代浏览器，比如Chrome、Firefox、Safari等。</div>
<![endif]-->

<div id="wrap">
    <header  style="position: absolute;" >
    <div id="site-meta">
        <a href="/" id="logo">
            <h1 class="title">MIAbon&#39;s blog</h1>
        </a>
        
    </div>
    <ul id="nav">
        
            <li><a href="/"><i class="fa fa-home"></i>首页</a></li>
        
            <li><a href="/atom.xml"><i class="fa fa-rss"></i>RSS</a></li>
        
        <li id="search"><a href="javascript:void(0)"><i class="fa fa-search"></i>搜索</a></li>
    </ul>
</header>

    <div id="container">
        
<ul id="sidebar">
    
    
    
    
<li class="widget widget-normal category">
    <h3 class="fa fa-th widget-title">分类</h3>
    <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/ELK/"><i class="fa" aria-hidden="true">ELK</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Lvs/"><i class="fa" aria-hidden="true">Lvs</i></a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/admin/"><i class="fa" aria-hidden="true">admin</i></a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/ansible/"><i class="fa" aria-hidden="true">ansible</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/aws/"><i class="fa" aria-hidden="true">aws</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/docker/"><i class="fa" aria-hidden="true">docker</i></a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/drone/"><i class="fa" aria-hidden="true">drone</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/kernel/"><i class="fa" aria-hidden="true">kernel</i></a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/kubernetes/"><i class="fa" aria-hidden="true">kubernetes</i></a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/kvm/"><i class="fa" aria-hidden="true">kvm</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mongodb/"><i class="fa" aria-hidden="true">mongodb</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link current" href="/categories/python/"><i class="fa" aria-hidden="true">python</i></a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/share/"><i class="fa" aria-hidden="true">share</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/web/"><i class="fa" aria-hidden="true">web</i></a><span class="category-list-count">12</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/zabbix/"><i class="fa" aria-hidden="true">zabbix</i></a><span class="category-list-count">3</span></li></ul>
</li>


    
    
<li class="widget widget-normal archive">
  <h3 class="fa fa-archive widget-title">归档</h3>
    <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/02/"><i class="fa" aria-hidden="true">二月 2018</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/"><i class="fa" aria-hidden="true">一月 2018</i></a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/"><i class="fa" aria-hidden="true">十二月 2017</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/"><i class="fa" aria-hidden="true">十一月 2017</i></a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/"><i class="fa" aria-hidden="true">十月 2017</i></a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/"><i class="fa" aria-hidden="true">九月 2017</i></a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/"><i class="fa" aria-hidden="true">八月 2017</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/"><i class="fa" aria-hidden="true">五月 2017</i></a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/"><i class="fa" aria-hidden="true">四月 2017</i></a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/"><i class="fa" aria-hidden="true">三月 2017</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/01/"><i class="fa" aria-hidden="true">一月 2017</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/12/"><i class="fa" aria-hidden="true">十二月 2016</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/11/"><i class="fa" aria-hidden="true">十一月 2016</i></a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/10/"><i class="fa" aria-hidden="true">十月 2016</i></a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/"><i class="fa" aria-hidden="true">八月 2016</i></a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/05/"><i class="fa" aria-hidden="true">五月 2016</i></a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/"><i class="fa" aria-hidden="true">四月 2016</i></a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/05/"><i class="fa" aria-hidden="true">五月 2015</i></a><span class="archive-list-count">1</span></li></ul>
</li>


    
    
<li class="widget widget-normal tags">
  <h3 class="fa fa-tags widget-title">标签云</h3>
  <div class="tagcloud-content">
    
      <a href="/tags/drone/" style="font-size: 0.14rem; color: #69c">drone</a> <a href="/tags/linux/" style="font-size: 0.2rem; color: #0a407c">linux</a> <a href="/tags/kernel/" style="font-size: 0.16rem; color: #4f83b8">kernel</a> <a href="/tags/ELK/" style="font-size: 0.14rem; color: #69c">ELK</a> <a href="/tags/ansible/" style="font-size: 0.14rem; color: #69c">ansible</a> <a href="/tags/swarm/" style="font-size: 0.14rem; color: #69c">swarm</a> <a href="/tags/docker/" style="font-size: 0.18rem; color: #215690">docker</a> <a href="/tags/firewalld/" style="font-size: 0.14rem; color: #69c">firewalld</a> <a href="/tags/zabbix/" style="font-size: 0.16rem; color: #4f83b8">zabbix</a> <a href="/tags/aws/" style="font-size: 0.14rem; color: #69c">aws</a> <a href="/tags/web/" style="font-size: 0.16rem; color: #4f83b8">web</a> <a href="/tags/python/" style="font-size: 0.18rem; color: #215690">python</a> <a href="/tags/spider/" style="font-size: 0.17rem; color: #386da4">spider</a>
  </div>
</li>


    
    
<li class="widget widget-normal friends-link">
    <h3 class="fa fa-globe widget-title">友链</h3><br/>

    
        <a href="http://zhengwei666.wang" class="fa" target="_blank">zhengwei</a>

    
        <a href="https://you-deng.github.io" class="fa" target="_blank">dengyou</a>

    
        <a href="http://www.systemd.cn" class="fa" target="_blank">langyaoliang</a>

    
        <a href="http://www.chen-hao.com.cn/" class="fa" target="_blank">chenhao</a>

    
        <a href="http://www.yulongjun.com" class="fa" target="_blank">yulongjun</a>

    

</li>

    
</ul>


        <div id="main">
    <article id="post">
        <div id="post-header">

            <h1 id="git_mark">
                
                git_mark
                
            </h1>
            <div class="article-meta">
    
    
    <span class="categories-meta fa-wrap">
            <i class="fa fa-folder-open-o"></i>
        <span>admin</span>
    </span>
    
    
    <span class="fa-wrap">
         <i class="fa fa-tags"></i>
        <span class="tags-meta">
            
            linux
            
        </span>
    </span>
    
    
    <span class="fa-wrap">
        <i class="fa fa-clock-o"></i>
        <span class="date-meta ">2017/11/29</span>
    </span>
    
    
    <span class="fa-wrap">
            <i class="fa fa-thermometer-three-quarters"></i>
        <span class="hits hits-meta " data-leadcloud-title="git_mark"
              data-leadcloud-url="/2017/11/29/git/"><i class="fa fa-spinner fa-spin"></i></span>
    </span>
    
    
</div>

            
            
        </div>
        
        <div id="post-body">
            <h1 id="Git的首次配置"><a href="#Git的首次配置" class="headerlink" title="Git的首次配置"></a>Git的首次配置</h1><p>Git 包含了一个叫作 git config 的工具，可以用来获取和设置配置变量，这些变量控制着 Git 外观和操作的方方面面。可以将配置变量存储在三个不同的位置。   </p>
<ol>
<li>/etc/gitconfig 文件：包含了系统中所有用户及仓库的值。如果你向 git  config 传入 –system 选项，那么它就会专门从该文件读写配置变量。   </li>
<li>~/.gitconfig 或 ~/.gitconfig/git/config 文件：针对的是你自己。你可以通过传入 –global 选项使 Git 专门从该文件中读写配置变量。</li>
<li>当前仓库的 Git 目录（也就是 .git/config ）中的 config 文件：针对单个仓库。</li>
</ol>
<h2 id="用户身份"><a href="#用户身份" class="headerlink" title="用户身份"></a>用户身份</h2><p>安装好 Git 后的第一件事就是设置用户名和电子邮件地址。这一步非常重要，因为 Git 的每一次提交都需要用到这些信息，而且还会被写入到所创建的提交中，不可更改。设置命令如下：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">$ git config --global user.name <span class="string">"xxx"</span></div><div class="line">$ git config --global user.email <span class="string">"xxx@xx.com"</span></div></pre></td></tr></table></figure></p>
<h2 id="检查个人设置"><a href="#检查个人设置" class="headerlink" title="检查个人设置"></a>检查个人设置</h2><p>如果想查看你的设置，可以通过执行 git config –list 命令来列出当前 Git 可以找到的所有设置<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git config --list</div></pre></td></tr></table></figure></p>
<h1 id="获取Git仓库"><a href="#获取Git仓库" class="headerlink" title="获取Git仓库"></a>获取Git仓库</h1><p>创建 Git 项目的方法主要有两种。第一种是把现有的项目或者目录导入到 Git 中，第二种是从服务器上克隆现有的 Git 仓库。</p>
<h2 id="在现有目录中初始化-Git-仓库"><a href="#在现有目录中初始化-Git-仓库" class="headerlink" title="在现有目录中初始化 Git 仓库"></a>在现有目录中初始化 Git 仓库</h2><p>想要在 Git 中对现有项目进行跟踪管理，只需要进入项目目录并输入：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git init</div></pre></td></tr></table></figure></p>
<p>这会创建一个名为 .git 的目录。这个子目录包含了构建 Git 仓库骨架的所有必须文件。但此刻 Git 尚未跟踪项目中的任何文件。<br>如果你打算着手对现有文件（非空目录）进行版本控制，那么就应该开始跟踪这些文件并进行初次提交。对需要跟踪的文件执行几次 git add 命令，然后输入 git commit 命令即可：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">$ git add *</div><div class="line">$ git commit -m <span class="string">"deploy"</span></div></pre></td></tr></table></figure></p>
<h3 id="Git-Add"><a href="#Git-Add" class="headerlink" title="Git Add"></a>Git Add</h3><p>git add 命令是将工作目录中的内容添加到暂存区（或 “索引”），以备下次提交。git commit 命令在执行时，默认只查看暂存区，因此 git add 的执行结果与下一次提交的快照一模一样。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ git add fileName</div><div class="line"><span class="comment">#或者</span></div><div class="line">$ git add .</div></pre></td></tr></table></figure></p>
<h3 id="Git-Clone"><a href="#Git-Clone" class="headerlink" title="Git Clone"></a>Git Clone</h3><h4 id="HTTP-Clone"><a href="#HTTP-Clone" class="headerlink" title="HTTP Clone"></a>HTTP Clone</h4><h4 id="SSH-Clone"><a href="#SSH-Clone" class="headerlink" title="SSH Clone"></a>SSH Clone</h4><p>需要配合gogs | gitea | gitlab等使用   </p>
<h3 id="Git-ignore"><a href="#Git-ignore" class="headerlink" title="Git ignore"></a>Git ignore</h3><h4 id="ignore-忽略同步内容"><a href="#ignore-忽略同步内容" class="headerlink" title="ignore 忽略同步内容"></a>ignore 忽略同步内容</h4><p>ignore 是用来忽略某些文件或者目录同步远成仓库的，通常在根目录下<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line"><span class="comment"># Ignore paths that contain user-generated content.</span></div><div class="line">/cache</div><div class="line">/files/*</div><div class="line"><span class="comment"># Packages #</span></div><div class="line"><span class="comment">############</span></div><div class="line">*.7z</div><div class="line">*.dmg</div><div class="line">*.gz</div><div class="line">*.bz2</div><div class="line">*.iso</div><div class="line">*.jar</div><div class="line">*.rar</div><div class="line">*.tar</div><div class="line">*.zip</div><div class="line">*.tgz</div><div class="line"><span class="comment"># Logs and databases #</span></div><div class="line"><span class="comment">######################</span></div><div class="line">*.<span class="built_in">log</span></div><div class="line">*.sql</div><div class="line"><span class="comment"># OS generated files #</span></div><div class="line"><span class="comment">######################</span></div><div class="line">.DS_Store*</div><div class="line">ehthumbs.db</div><div class="line">Icon</div><div class="line">Thumbs.db</div><div class="line">._*</div><div class="line"><span class="comment"># Vim generated files #</span></div><div class="line"><span class="comment">######################</span></div><div class="line">*.un~</div></pre></td></tr></table></figure></p>
<p>如果 ignore 同步不生效，清理缓存后重试<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git rm -r --cached</div></pre></td></tr></table></figure></p>
<h3 id="Git-Remote"><a href="#Git-Remote" class="headerlink" title="Git Remote"></a>Git Remote</h3><h4 id="远程仓库的使用"><a href="#远程仓库的使用" class="headerlink" title="远程仓库的使用"></a>远程仓库的使用</h4><p>要参与任何一个 Git 项目的写作，需要了解如何管理远程仓库，远程仓库是指在互联网其他网络上托管的项目版本仓库。可以拥有多个远程仓库，而对于其中每个仓库，可以拥有只读权限或者读写权限。要同别人写作，就要管理这些远程仓库，在需要分享工作成果时，向其推送数据，从中拉取数据。管理远程仓库需要知道如何添加远程仓库、移除无效的远程仓库、管理各种远程分支和设置是否跟踪这些分支，等等。   </p>
<h4 id="显示远程仓库"><a href="#显示远程仓库" class="headerlink" title="显示远程仓库"></a>显示远程仓库</h4><p>要查看已经设置了那些远成仓库，请使用 git remote 命令。该命令会列出每个远程仓库的简短名称。在克隆某个仓库之后，至少可以看到名为 origin 的远程仓库，这是 Git 给克隆源服务器取名的默认名称。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">clone</span> http://git.geasslinks.com/miabon/blog.git</div><div class="line">$ <span class="built_in">cd</span> blog</div><div class="line">$ git remote</div><div class="line">origin</div></pre></td></tr></table></figure></p>
<p>也可以使用 -v 参数，这样会显示出 Git 存储的每个远程仓库对应的 URL：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ git remote -v</div><div class="line">origin  http://git.geasslinks.com/miabon/blog.git (fetch)</div><div class="line">origin  http://git.geasslinks.com/miabon/blog.git (push)</div></pre></td></tr></table></figure></p>
<p>如果有不止一个远程仓库，上面的命令会把他们都列出来。例如，为便于同多人协作，一个仓库会拥有多个远程仓库地址，看起来会像下面这样：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">$ git remote -v</div><div class="line">gerrit  ssh://git@192.168.114.170:29418/devops2 (fetch)</div><div class="line">gerrit  ssh://git@192.168.114.170:29418/devops2 (push)</div><div class="line">origin  git@192.168.114.170:demo/devops2.git (fetch)</div><div class="line">origin  git@192.168.114.170:demo/devops2.git (push)</div></pre></td></tr></table></figure></p>
<h4 id="添加远程仓库"><a href="#添加远程仓库" class="headerlink" title="添加远程仓库"></a>添加远程仓库</h4><p>要添加一个远程仓库，并给他起一个简短名称以便引用，可以执行:<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git remote add [shortname] [url]</div></pre></td></tr></table></figure></p>
<p>example<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">$ git remote</div><div class="line">origin</div><div class="line">$ git remote add myblog http://git.geasslinks.com/miabon/blog.git</div><div class="line">$ git remote -v</div><div class="line">myblog	http://git.geasslinks.com/miabon/blog.git (fetch)</div><div class="line">myblog	http://git.geasslinks.com/miabon/blog.git (push)</div><div class="line">origin	http://git.geasslinks.com/miabon/blog.git (fetch)</div><div class="line">origin	http://git.geasslinks.com/miabon/blog.git (push)</div></pre></td></tr></table></figure></p>
<p>现在可以在命令行中使用 myblog 字符串代替完整的 URL。比如，要获取未拥有的其他远程仓库内的数据，可以执行 git fetch blog 命令：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">$ git fetch myblog</div><div class="line">warning: no common commits</div><div class="line">remote: Counting objects: 406, <span class="keyword">done</span>.</div><div class="line">remote: Total 406 (delta 0), reused 0 (delta 0), pack-reused 406</div><div class="line">Receiving objects: 100% (406/406), 3.11 MiB | 8.00 KiB/s, <span class="keyword">done</span>.</div><div class="line">Resolving deltas: 100% (223/223), <span class="keyword">done</span>.</div><div class="line">From http://git.geasslinks.com/miabon/blog.git</div><div class="line"> * [new branch]      docker-elasticsearch    -&gt; myblog/docker-elasticsearch</div><div class="line"> * [new branch]      docker-mongo            -&gt; myblog/docker-mongo</div><div class="line"> * [new branch]      login-pull-mongo-cookie -&gt; myblog/login-pull-mongo-cookie</div><div class="line"> * [new branch]      login-pull-one          -&gt; myblog/login-pull-one</div><div class="line"> * [new branch]      login-pull-repeatedly   -&gt; myblog/login-pull-repeatedly</div><div class="line"> * [new branch]      master                  -&gt; myblog/master</div></pre></td></tr></table></figure></p>
<p>现在可以在本地使用 myblog/master 的名称访问到 mastr 分支的数据，还可以把它与本地的某一个分支进行合并，或是检出一个本地分支便于检查其中的更改。</p>
<h4 id="从远程仓库获取和拉去数据"><a href="#从远程仓库获取和拉去数据" class="headerlink" title="从远程仓库获取和拉去数据"></a>从远程仓库获取和拉去数据</h4><p>要从远程项目获取数据，可以执行：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git fetch [remote-name]</div></pre></td></tr></table></figure></p>
<p>这条命令从远程仓库中获取所有本地仓库没有的数据。在执行上述命令后，就可以在本地引用远程仓库包含的所有分支，并可以在任何时候合并或检查这些分支。<br>当克隆仓库是，克隆命令会自动添加远程仓库的地址并取名为 “origin”。当随后执行 git fetch origin 时，会获取到所有自上次克隆（或获取）之后被推送到服务器端的新增的变更数据。请注意，git fetch 命令指挥吧数据拉取到本地仓库，然而他并不会自动将这些数据合并到本地的工作成果中，也不会修改当前工作目录下的任何数据。在准备好之后，需要手动将这些数据合并到本地内容中。<br>如果有一个跟踪着某个远程分支的本地分支，可以使用 git pull 命令来自动获取远程数据，并将远程分支合并入当前本地分支。而且默认情况下，git clone 命令会自动设置本地 master 分支，使其跟踪被克隆的服务器端的 master 分支（或是其他名称的默认远程分支）。这时候，执行 git pull 就会从被克隆的服务器上获取更新的数据，然后自动尝试将其合并入当前工作目录下的本地数据。</p>
<h4 id="将数据推送到远程仓库"><a href="#将数据推送到远程仓库" class="headerlink" title="将数据推送到远程仓库"></a>将数据推送到远程仓库</h4><p>当项目进行到某个阶段，需要与他人分析你的工作成果时，就要把变更推送到远程仓库去。用到的命令也很简单：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git push [remote-name] [branch-name]</div></pre></td></tr></table></figure></p>
<p>如果想把本地的 master 分支推送到远程的 origin 服务器上，那么可以执行下面的命令，把任意提交推送到服务器端：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git push origin master</div></pre></td></tr></table></figure></p>
<p>上述命令能够正常工作的前提是必须拥有克隆下来的远程仓库的写权限，并且克隆后没有任何其他人向远程仓库推送过数据。如果别人和你都克隆了这个仓库，而他县推送，你后推送，那么你的这次推送会直接被拒绝，你需要先拉取别人的变更，将其整合到你的工作成果中，任何才能推送。</p>
<h4 id="检查远程仓库"><a href="#检查远程仓库" class="headerlink" title="检查远程仓库"></a>检查远程仓库</h4><p>要查看关于某一远程仓库的更多信息，可以使用：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git remote show [remote-name]</div></pre></td></tr></table></figure></p>
<p>如果给改名了提供一个仓库的短名称，比如 origin，就会看到如下输出：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">* remote origin</div><div class="line">  Fetch URL: http://git.geasslinks.com/miabon/blog.git</div><div class="line">  Push  URL: http://git.geasslinks.com/miabon/blog.git</div><div class="line">  HEAD branch: master</div><div class="line">  Remote branches:</div><div class="line">    dev    tracked</div><div class="line">    master tracked</div><div class="line">  Local branch configured <span class="keyword">for</span> <span class="string">'git pull'</span>:</div><div class="line">    master merges with remote master</div><div class="line">  Local ref configured <span class="keyword">for</span> <span class="string">'git push'</span>:</div><div class="line">    master pushes to master (up to date)</div></pre></td></tr></table></figure></p>
<p>上述命令列出了远程仓库的 URL 地址以及每个分支的跟踪信息。这条命令会输出一些很有帮助的信息，比如告诉在 master 上执行 git pull 或获取到所有的远程引用，然后自动合并入 master 分支。它还显示了拉去下来的所有远程引用的信息。<br>上述示例给出的是一种简单的情况。当大量使用 Git 时，git remote show 可能会给出非常多的信息。</p>
<h4 id="删除和重命名远程仓库"><a href="#删除和重命名远程仓库" class="headerlink" title="删除和重命名远程仓库"></a>删除和重命名远程仓库</h4><p>可以用 git remote rename 来重命名远程仓库。如果想要把 myblog 重命名 testblog，可以用 git remote rename 命令来实现，如下所示：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">$ git remote rename myblog testblog</div><div class="line">$ git remote</div><div class="line">origin</div><div class="line">testblog</div></pre></td></tr></table></figure></p>
<p>上述操作也会更改远程分支的名称。先前的 myblog/master 分支现在就变为 testblog/master。</p>
<p>有时处于某种原因，需要删除某个远程仓库地址，比如当你迁移了服务器地址，或是不在使用某一仓库镜像，又或是某个参与者退出协作时，就可以使用 git remote rm 命令，如下所示：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ git remote rm testblog</div><div class="line">$ git remote</div><div class="line">origin</div></pre></td></tr></table></figure></p>
<h3 id="Git-commit"><a href="#Git-commit" class="headerlink" title="Git commit"></a>Git commit</h3><p>git commit 命令接受由 git add 暂存的所有文件内容，并在数据库中记录一份新的永久性快照，然后将当前分支的指针指向它。   </p>
<h3 id="Git-push"><a href="#Git-push" class="headerlink" title="Git push"></a>Git push</h3><p>Push 的操作是在提交代码到远程的操作，通常执行为：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git push</div></pre></td></tr></table></figure></p>
<p>如果提交不同的远程仓库应为：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git push -u origin master</div></pre></td></tr></table></figure></p>
<p>如果是新创建的 Branch ，需要执行：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">$ git checkout -b dev</div><div class="line">$ git push --<span class="built_in">set</span>-upstream origin dev</div></pre></td></tr></table></figure></p>
<p>如果 Push 操作出现了冲突：<br>可以用下面的两种方法。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#</span></div><div class="line">$ git pull</div><div class="line">$ git push</div><div class="line"><span class="comment">#</span></div><div class="line">$ git fetch origin</div><div class="line"><span class="comment"># 添加更多的开发历史</span></div><div class="line">$ git merge origin/dev</div><div class="line">$ git push</div></pre></td></tr></table></figure></p>
<p>如果想要推送到远程不同的分支，可以执行：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git push -u origin dev:dev1</div></pre></td></tr></table></figure></p>
<h3 id="Git-Pull"><a href="#Git-Pull" class="headerlink" title="Git Pull"></a>Git Pull</h3><h4 id="Pull-冲突问题"><a href="#Pull-冲突问题" class="headerlink" title="Pull 冲突问题"></a>Pull 冲突问题</h4><p>有时在使用 git pull 时会存在冲突的问题，解决的办法是使用 stash 命令<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git stash</div></pre></td></tr></table></figure></p>
<p>然后调用历史即可看到冲突的版本<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git stash list</div></pre></td></tr></table></figure></p>
<p>还原版本<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">$ git stash pop <span class="comment"># or</span></div><div class="line">$ git stash pop stash@&#123;0&#125;</div></pre></td></tr></table></figure></p>
<p>修改过的内容就回来了。并且解决的同步冲突的问题。</p>
<h4 id="Pull-完全覆盖"><a href="#Pull-完全覆盖" class="headerlink" title="Pull 完全覆盖"></a>Pull 完全覆盖</h4><p>对所有的冲突或者其他需求进行远程完整同步<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ git fetch --all</div><div class="line">$ git reset --hard origin/master</div><div class="line">$ git pull</div></pre></td></tr></table></figure></p>
<h3 id="Git-Stash"><a href="#Git-Stash" class="headerlink" title="Git Stash"></a>Git Stash</h3><p>通常当你的处理项目的某一部分时，方方面面的事情还没有理清，这时候你想转到其他分支上忙些别的事情。问题阿紫与你不希望把先前只做了一半的工作提交，因为随后还想回头接着做。解决这个问题的方法就是 git statsh 命令。<br>储藏（stashing）能够获得工作目录的中间状态，也就是修改过的被跟踪的文件以及暂存的变更，并将该中间状态保存在一个保存尚未完成变更的栈中，随后可以再次恢复这些状态。</p>
<h4 id="储藏工作成果"><a href="#储藏工作成果" class="headerlink" title="储藏工作成果"></a>储藏工作成果</h4><p>在项目中创建如下示例，有可能会有暂存的文件或者是变更的，如果执行 git status 可以看到如下状态：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">$ <span class="built_in">echo</span> README &gt; README.md</div><div class="line">$ <span class="built_in">echo</span> index &gt; index.html</div><div class="line">$ git add .</div><div class="line">$ <span class="built_in">echo</span> RE_README &gt; README.md</div><div class="line">$ git status</div><div class="line">On branch master</div><div class="line">Initial commit</div><div class="line">Changes to be committed:</div><div class="line">  (use <span class="string">"git rm --cached &lt;file&gt;..."</span> to unstage)</div><div class="line">    new file:   README.md</div><div class="line">    new file:   index.html</div><div class="line">Changes not staged <span class="keyword">for</span> commit:</div><div class="line">  (use <span class="string">"git add &lt;file&gt;..."</span> to update what will be committed)</div><div class="line">  (use <span class="string">"git checkout -- &lt;file&gt;..."</span> to discard changes <span class="keyword">in</span> working directory)</div><div class="line">    modified:   README.md</div></pre></td></tr></table></figure></p>
<p>现在你打算切换分支，但又不想把刚才的内容提交，那些可以储藏这些变更。执行 git stash 或者 git stash save 将新的储藏内容推入栈中，如下所示。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">$ git stash</div><div class="line">Saved working directory and index state WIP on master: 297b315 add *</div></pre></td></tr></table></figure>
<p>现在的工作目录就干净了，变成未修改之前的样子了：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">$ git status</div><div class="line">On branch master</div><div class="line">Your branch is up-to-date with <span class="string">'origin/master'</span>.</div><div class="line">nothing to commit, working tree clean</div></pre></td></tr></table></figure></p>
<p>这时可以方便的切换到起到分支工作，之前的变更就被保存在了栈中。要查看存储的栈中的储藏，可以使用 git statsh list 命令，如下所示。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">$ git stash list</div><div class="line">stash@&#123;0&#125;: WIP on master: 297b315 add *</div><div class="line">$ git stash apply</div><div class="line">On branch master</div><div class="line">Your branch is up-to-date with <span class="string">'origin/master'</span>.</div><div class="line">Changes to be committed:</div><div class="line">  (use <span class="string">"git reset HEAD &lt;file&gt;..."</span> to unstage)</div><div class="line">    new file:   README.md</div><div class="line">    new file:   index.html</div></pre></td></tr></table></figure></p>
<p>可以看到，当保存储藏时，Git 重新修改了当时尚未提交的文件。在本例中，工作目录在应用储藏时（应用的分支和保存储藏时的分支相同）是干净的；但是一个干净的工作目录以及应用在相同分支上并非成功应用储藏的必要条件。可以在一个分支上保存储藏，然后切换到另一个分支，重新应用这些变更。在应用储藏时，工作目录中也可以包含已修改和未提交的文件，只要无法干净利落应用任何操作，Git 都会给出合并冲突信息。</p>
<p>文件变更可以重新应用，但是之前暂存过的文件却不会被再次暂存。要想这样，你需要使用 –index 选项的 git stash apply 命令，告诉该命令重新应用暂存过的变更。执行过这条命了之后，你就会回到原先的状态，如下：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git stash apply --index</div></pre></td></tr></table></figure></p>
<p>如下想要删除某一次储藏，可以使用以下方式：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ git stash list</div><div class="line">stash@&#123;0&#125;: WIP on master: 297b315 add *</div><div class="line">$ git stash drop stash<span class="variable">$&#123;0&#125;</span></div></pre></td></tr></table></figure></p>
<h4 id="使用储存内容"><a href="#使用储存内容" class="headerlink" title="使用储存内容"></a>使用储存内容</h4><p>在存储后，可以使用 pop 参数打开储存的内容：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git stash pop</div></pre></td></tr></table></figure></p>
<p>可以选择使用哪个：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git stash pop stash@&#123;0&#125;</div></pre></td></tr></table></figure></p>
<h3 id="Git-Clean"><a href="#Git-Clean" class="headerlink" title="Git Clean"></a>Git Clean</h3><h4 id="Git-清理工作目录"><a href="#Git-清理工作目录" class="headerlink" title="Git 清理工作目录"></a>Git 清理工作目录</h4><p>对于工作目录中的一些工作成果获文件，你想要做的可能并不是储藏，而是把它们弄走，git clean 命令可以做到这一点。<br>这种做法的一些常见原因包括删除由合并操作或外部工工具产生的杂乱文件，或是执行洁净的构建之前清理构建产物。<br>使用这条命令的时候可要千万小心，因为它会从工作目录中删除所有未跟踪过的文件。就算你改变了注意，这些文件多半也是找不回来了，一个更安全的选择执行 git stash –all 来删除全部内容，溶蚀将其以储藏的形式保存。<br>假设你想删除杂乱文件或是清理工作目录，可以使用 git clean。要删除工作目录中的所有未跟踪文件，可以使用：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git clean -f -d</div></pre></td></tr></table></figure></p>
<p>该命令会将文件全部删除并清空所有的子目录。-f 表示 ”强制“（force）或 ”确定执行“（really do this）。<br>如果你想看看这条命令到底做了什么，可以加入选项 -n，该选项表示 ”做一次演习，告诉你都会删除什么“：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ <span class="built_in">echo</span> file &gt; fileName</div><div class="line">$ git clean -d -n</div><div class="line">Would remove fileName</div></pre></td></tr></table></figure></p>
<p>git clean 命令默认只删除没有被忽略的未跟踪文件。任何与 .gitignore 或其他忽略文件中模式匹配的文件都不会被删除。如果连这些文件也想删除，例如为了完成一次全面的洁净构建，需要删除由构建生成的 .o 文件，那么你可以在 clean 命令中加入 -x 选项。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">$ git clean -d -n -x</div><div class="line">Would remove fileName.o</div></pre></td></tr></table></figure></p>
<p>如果不清楚 git clean 命令都会做些什么，可以先加入 -n 选项确无误，然后再把 -n 改为 -f 进行实际的操作。另一种安全的做法是执行命令的时候加入 -i（interactive）选项。<br>该选项会使得 clean 命令以交互模式执行，如下所示。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git clean -x -i</div></pre></td></tr></table></figure></p>
<h3 id="Git-Grep"><a href="#Git-Grep" class="headerlink" title="Git Grep"></a>Git Grep</h3><h4 id="Git搜索"><a href="#Git搜索" class="headerlink" title="Git搜索"></a>Git搜索</h4><p>无论代码库有多大，你经常都会需要找出某个函数的调用位置或定义位置，或者某个方法的变更历史。Git 提供了一些工具，能够方便快速的查找存储在数据库中的代码和提交。下面就来看看其中几个工具。</p>
<h5 id="Git-Grep-1"><a href="#Git-Grep-1" class="headerlink" title="Git Grep"></a>Git Grep</h5><p>Git 自带了一个叫做 grep 的命令，该命令可以在任何提交树或工作目录中方便的查找某个自处罚或正则表达式。<br>在默认情况下，Grep 只查找工作目录下的文件。你可以使用 -n 选项来输出匹配位置的行号。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ git grep -n ENTRYPOINT</div><div class="line">Dockerfile:37:ENTRYPOINT [<span class="string">"java"</span>,<span class="string">"-Djava.security.egd=file:/dev/urandom"</span>,<span class="string">"-jar"</span>,<span class="string">"./app.jar"</span>, <span class="string">"--port=80"</span>]</div><div class="line">docker/Dockerfile:6:ENTRYPOINT [<span class="string">"java"</span>,<span class="string">"-Djava.security.egd=file:/dev/urandom"</span>,<span class="string">"-jar"</span>,<span class="string">"./app.jar"</span>, <span class="string">"--port=80"</span>]</div></pre></td></tr></table></figure></p>
<p>grep 命令有很多值得一提的选项。<br>例如，与上面的例子不同，你可以使用 –count 选项让 Git 输出总结信息：匹配到了那些文件，每个匹配文件中有多少处匹配，如下所示。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ git grep --count ENTRYPOINT</div><div class="line">Dockerfile:1</div><div class="line">docker/Dockerfile:1</div></pre></td></tr></table></figure></p>
<p>如果想看看所查找到的匹配属于哪个方法或函数，可以使用 -p 选项，如下，意思是 customerId 这个字符串在 api-spec 目录下的所有 json 中进行搜索：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">$ git grep -p customerId api-spec/*.json</div><div class="line">api-spec/cart.json:      <span class="comment">#  "/carts/&#123;customerId&#125;": &#123;</span></div><div class="line">api-spec/cart.json:      <span class="comment">#               "name": "customerId",</span></div><div class="line">api-spec/cart.json:      <span class="comment">#               "name": "customerId",</span></div><div class="line">api-spec/cart.json:      <span class="comment">#  "/carts/&#123;customerId&#125;/items": &#123;</span></div><div class="line">api-spec/cart.json:      <span class="comment">#               "name": "customerId",</span></div><div class="line">api-spec/cart.json:      <span class="comment">#               "name": "customerId",</span></div><div class="line">api-spec/cart.json:      <span class="comment">#  "/carts/&#123;customerId&#125;/items/&#123;itemId&#125;": &#123;</span></div><div class="line">api-spec/cart.json:      <span class="comment">#               "name": "customerId",</span></div><div class="line">api-spec/cart.json:      <span class="comment">#       "customerId": &#123;</span></div><div class="line">api-spec/cart.json:      <span class="comment">#       "customerId"</span></div></pre></td></tr></table></figure></p>
<h3 id="Git-Log"><a href="#Git-Log" class="headerlink" title="Git Log"></a>Git Log</h3><p>在进入 Git 工作目录内后可以使用 git log 查看历史记录，这可以是 clone 或者未执行 push 操作的数据源目录，例如这里使用 clone 的目录：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">clone</span> http://git.geasslinks.com/miabon/blog.git</div></pre></td></tr></table></figure></p>
<p>进入目录内执行 git log 会看到以下输出：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">commit e080071b5a46b1118dccd3e55105ad226f6dbe72</div><div class="line">Author: miabon &lt;werewolf2101@gmail.com&gt;</div><div class="line">Date:   Tue Dec 12 10:34:26 2017 +0800</div><div class="line">    blog</div><div class="line">commit 4f396ea98a856310ec93761787f5340ccd6b48df</div><div class="line">Author: miabon &lt;werewolf2101@gmail.com&gt;</div><div class="line">Date:   Tue Dec 12 10:32:09 2017 +0800</div><div class="line">    blog</div></pre></td></tr></table></figure></p>
<p>默认不加参数的情况下，git log 会按照时间顺序列出仓库中的所有提交，其中最新的提交显示在最前面。如你所见，和每个提交一同列出的还有它的 SHA-1 效验和、作者的姓名和邮箱、提交日期以及提交信息。   </p>
<p>git log 有很多不同的选项，可以直观的展示出所需内容。现在来看一些最常用的选项。   </p>
<p>最有用的一个选项是 -p，它会显示出每次提交所引入的差异。还可以加上 -2 参数，只输出最近的两次提交：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div></pre></td><td class="code"><pre><div class="line">commit e080071b5a46b1118dccd3e55105ad226f6dbe72</div><div class="line">Author: miabon &lt;werewolf2101@gmail.com&gt;</div><div class="line">Date:   Tue Dec 12 10:34:26 2017 +0800</div><div class="line">    blog</div><div class="line">diff --git <span class="string">"a/2016/10/31/mongodb\351\233\206\347\276\244\345\256\211\350\243\205/index.html"</span> <span class="string">"b/2016/10/31/mongodb\351\233\206\347\276\244\345\256\211\350\243\205/index.html"</span></div><div class="line">index 879e117..635ecd9 100644</div><div class="line">--- <span class="string">"a/2016/10/31/mongodb\351\233\206\347\276\244\345\256\211\350\243\205/index.html"</span></div><div class="line">+++ <span class="string">"b/2016/10/31/mongodb\351\233\206\347\276\244\345\256\211\350\243\205/index.html"</span></div><div class="line">@@ -286,7 +286,7 @@</div><div class="line">     &lt;/article&gt;</div><div class="line">     &lt;div class=<span class="string">"article-nav"</span>&gt;</div><div class="line">-        &lt;a href=<span class="string">"/2016/11/29/oh_my_zsh/"</span> class=<span class="string">"pre-post fa fa-caret-left"</span>&gt;oh my zsh&lt;/a&gt;</div><div class="line">+        &lt;a href=<span class="string">"/2016/11/28/oh_my_zsh/"</span> class=<span class="string">"pre-post fa fa-caret-left"</span>&gt;oh my zsh&lt;/a&gt;</div><div class="line">         &lt;a href=<span class="string">"/2016/10/26/在EC2_Linux上挂载S3存储桶/"</span> class=<span class="string">"next-post fa"</span>&gt;在EC2 Linux上挂载S3存储桶&lt;/a&gt;</div><div class="line">diff --git a/2016/11/28/oh_my_zsh/index.html b/2016/11/28/oh_my_zsh/index.html</div><div class="line">new file mode 100644</div><div class="line">index 0000000..fafdfab</div><div class="line">--- /dev/null</div><div class="line">+++ b/2016/11/28/oh_my_zsh/index.html</div><div class="line">@@ -0,0 +1,386 @@</div><div class="line">+&lt;!doctype html&gt;</div><div class="line">+&lt;html&gt;</div><div class="line">+&lt;head&gt;</div><div class="line">+    &lt;!--Setting--&gt;</div><div class="line">+    &lt;meta charset=<span class="string">"UTF-8"</span>&gt;</div><div class="line">+    &lt;meta name=<span class="string">"viewport"</span> content=<span class="string">"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"</span>&gt;</div><div class="line">+    &lt;meta http-equiv=<span class="string">"X-UA-Compatible"</span> content=<span class="string">"ie=edge"</span>&gt;</div><div class="line">+    &lt;meta name=<span class="string">"renderer"</span> content=<span class="string">"webkit|ie-comp|ie-stand"</span>&gt;</div><div class="line">+    &lt;meta name=<span class="string">"apple-mobile-web-app-capable"</span>  content=<span class="string">"yes"</span>&gt;</div><div class="line">+    &lt;meta name=<span class="string">"apple-mobile-web-app-status-bar-style"</span> content=<span class="string">"black"</span>&gt;</div><div class="line">+    &lt;meta name=<span class="string">"format-detection"</span> content=<span class="string">"telephone=no,email=no"</span>&gt;</div><div class="line">+    </div><div class="line">+    </div><div class="line">+    &lt;!--Simple SEO--&gt;</div><div class="line">+</div><div class="line">+</div><div class="line">+&lt;meta name=<span class="string">"robots"</span> content=all /&gt;</div><div class="line">...</div></pre></td></tr></table></figure></p>
<p>加上这个选项之后，仍会显示原来的信息，不同之处是每一条提交记录后面都带有 diff 信息。在代码审查或是快速浏览某个项目参与者的一系列提交时，这个选项会非常有用。git log 还提供了一系列的摘要选项。例如，可以用 –stat 选项来查看每个提交的简要统计信息：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">log</span> --<span class="built_in">stat</span></div><div class="line">commit e080071b5a46b1118dccd3e55105ad226f6dbe72</div><div class="line">Author: miabon &lt;werewolf2101@gmail.com&gt;</div><div class="line">Date:   Tue Dec 12 10:34:26 2017 +0800</div><div class="line">    blog</div><div class="line"> <span class="string">"2016/10/31/mongodb\351\233\206\347\276\244\345\256\211\350\243\205/index.html"</span> |   2 +-</div><div class="line"> 2016/11/28/oh_my_zsh/index.html                                                 | 386 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</div><div class="line"> <span class="string">"2016/11/29/CentOS7\345\215\207\347\272\247\345\206\205\346\240\270/index.html"</span> |   2 +-</div><div class="line"> 2016/11/29/oh_my_zsh/index.html                                                 | 386 -------------------------------------------------------------------------------------------------------------------</div><div class="line"> archives/2016/11/index.html                                                     |   6 +-</div><div class="line"> archives/2016/index.html                                                        |   6 +-</div><div class="line"> archives/page/3/index.html                                                      |   6 +-</div><div class="line"> categories/admin/index.html                                                     |   6 +-</div><div class="line"> page/3/index.html                                                               |  10 +--</div><div class="line"> search.xml                                                                      |   2 +-</div><div class="line"> sitemap.xml                                                                     |   4 +-</div><div class="line"> tags/linux/page/2/index.html                                                    |   6 +-</div><div class="line"> 12 files changed, 411 insertions(+), 411 deletions(-)</div><div class="line">...</div></pre></td></tr></table></figure></p>
<p>–stat 选项会在每个提交下面列出如下内容：改动的文件列表、共有多少文件被改动以及文件里有多少新增行和删除行。另外还会在最后输出总计信息。<br>另外一个颇为有用的选项是 –pretty，它可以更改日志输出的默认格式。Git 有一些预配的格式提供选择。例如，在浏览大量提交时，oneline 格式选项很有用，它可以在每一行中显示一个提交。除此之外，short、full 和 fuller 格式选项分别比默认输出减少或增加一些信息：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">log</span> --pretty=oneline</div><div class="line">cdd5960b6b25f61151b5812eddae152b219739c7 (HEAD -&gt; master, origin/master, origin/HEAD) edit *</div><div class="line">479b9cf8ff06bb9d6aaddc8f97e2a03bf03ae38c edit *</div><div class="line">fa4dd85453596cfb026a34908887241f12ed516b edit *</div><div class="line">93bf57928301040f00a614bd5c8b96f30590eec7 Merge pull request <span class="comment">#2 from slzcc/html</span></div><div class="line">66ae8f9abad825434c6ce9dddc2f721bffe71b44 (origin/html) edit *</div><div class="line">7ba7089d41c095d6078f83ab2d7a421d3a5e33a9 edit *</div><div class="line">621eb7c9a81a05b5a4574415fc1cf4fb6711c586 edit *</div><div class="line">d82d5354cb912e34505d99e6614721a1ccb054cb Merge pull request <span class="comment">#1 from slzcc/html</span></div><div class="line">705654ce9757babd181b467311d070a9b9c2c038 edit *</div><div class="line">c306db7648cecef70fc8f95757182e92f9da99ad edit *</div><div class="line">68c7dc55f6ba5e472d8317ae9200a1f0c3b3286a add *</div><div class="line">92523b314b73389a785fb905d2ec019c7472459a add *</div><div class="line">...</div></pre></td></tr></table></figure></p>
<p>最值得注意的选项是 format，它允许你指定自己的输出格式。这样的输出特别有助于机器解析，因为可以明确指定输出格式，其结果不会随着 Git 软件版本更新而改变：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">log</span> --pretty=format:<span class="string">"%h - %an, %ar : %s"</span></div><div class="line">725c8d4 - DESKTOP-3OHAH7J\rqh, 5 days ago : 等等</div><div class="line">afe5cc8 - zhoushuo, 6 days ago : 啊</div><div class="line">dcd20ef - DESKTOP-3OHAH7J\rqh, 6 days ago : 等等</div><div class="line">97e54a8 - zhoushuo, 6 days ago : no message</div><div class="line">af7dcdb - zhoushuo, 7 days ago : 啊</div><div class="line">d63de02 - DESKTOP-3OHAH7J\rqh, 7 days ago : 等等</div><div class="line">3bb94e5 - DESKTOP-3OHAH7J\rqh, 7 days ago : 等等</div><div class="line">8bba3e9 - DESKTOP-3OHAH7J\rqh, 7 days ago : 等等</div><div class="line">3479702 - zhoushuo, 7 days ago : 啊</div><div class="line">2513cd6 - DESKTOP-3OHAH7J\rqh, 7 days ago : 等等</div><div class="line">c482573 - zhoushuo, 7 days ago : 啊</div><div class="line">22e4cb7 - DESKTOP-3OHAH7J\rqh, 8 days ago : 对对对</div><div class="line">12ffa14 - DESKTOP-3OHAH7J\rqh, 8 days ago : 等等</div><div class="line">50be537 - DESKTOP-3OHAH7J\rqh, 8 days ago : 等等</div><div class="line">1692055 - zhoushuo, 11 days ago : 啊</div><div class="line">f6bb99f - zhoushuo, 11 days ago : 啊</div><div class="line">abbdf83 - zhoushuo, 11 days ago : 啊</div><div class="line">5d39ac6 - tevin, 11 days ago : no message</div><div class="line">16721dd - tevin, 11 days ago : no message</div><div class="line">23282d4 - tevin, 11 days ago : no message</div><div class="line">...</div></pre></td></tr></table></figure></p>
<h4 id="搜索特定作者的提交。-可以是字符串或正则表达式。"><a href="#搜索特定作者的提交。-可以是字符串或正则表达式。" class="headerlink" title="搜索特定作者的提交。 可以是字符串或正则表达式。"></a>搜索特定作者的提交。<pattern> 可以是字符串或正则表达式。</pattern></h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">log</span> --author=<span class="string">"&lt;pattern&gt;"</span></div></pre></td></tr></table></figure>
<h4 id="搜索提交信息匹配特定-的提交。-可以是字符串或正则表达式"><a href="#搜索提交信息匹配特定-的提交。-可以是字符串或正则表达式" class="headerlink" title="搜索提交信息匹配特定  的提交。 可以是字符串或正则表达式"></a>搜索提交信息匹配特定 <pattern> 的提交。<pattern> 可以是字符串或正则表达式</pattern></pattern></h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">log</span> --grep=<span class="string">"&lt;pattern&gt;"</span></div></pre></td></tr></table></figure>
<h4 id="显示代表每个提交的一堆信息。显示每个提交全部的差异（diff），这也是项目历史中最详细的视图。"><a href="#显示代表每个提交的一堆信息。显示每个提交全部的差异（diff），这也是项目历史中最详细的视图。" class="headerlink" title="显示代表每个提交的一堆信息。显示每个提交全部的差异（diff），这也是项目历史中最详细的视图。"></a>显示代表每个提交的一堆信息。显示每个提交全部的差异（diff），这也是项目历史中最详细的视图。</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">log</span> -p</div></pre></td></tr></table></figure>
<h4 id="查看当前所在分支的-HEAD"><a href="#查看当前所在分支的-HEAD" class="headerlink" title="查看当前所在分支的 HEAD"></a>查看当前所在分支的 HEAD</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">log</span> --oneline --decorate</div></pre></td></tr></table></figure>
<p>如果出现了分叉，可以使用下面的命令进行查看：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">log</span> --oneline --decorate --graph --all</div><div class="line">* eb317c952a Fix PowerShell escaping and update <span class="keyword">for</span> DockerProvider</div><div class="line">* 73c9bef3ad Update page variable</div><div class="line">* 60286e718b Clarify <span class="built_in">where</span> signing and verification happen</div><div class="line">* 4bbaa46993 Get started part 2: How to access app <span class="keyword">in</span> container on Windows 7 Docker Toolbox</div><div class="line">* 21642e926c Example overlay IPs consistency</div><div class="line">* 06e64aaefe add placement pref note about null labels</div><div class="line">| * 75469a6280 (origin/fasttree) Move <span class="built_in">functions</span> and vars to toc.js</div><div class="line">| * 2c9493642e Collections support</div><div class="line">| * fdcf160e89 Glossary support</div><div class="line">| * 176dc69e3e Remove jekyll-seo -- even more perf gain</div><div class="line">| * 0199327d5d More YML simplification</div><div class="line">| * e84c03542c Simplifying authoring YML even more</div><div class="line">| * a783351071 Removing dk.rb artifact</div><div class="line">| * c77f0d366c Update Gemfile</div><div class="line">| * 2a5bfc26fa GHPages 147, authoring YML, sitemap via plugin, working JS</div><div class="line">| * e09811d47a rough pass at tabs, jsonification</div><div class="line">| | * 987907418c (origin/vnext-engine) Add new debian &amp; ubuntu edge support</div><div class="line">| |/</div><div class="line">|/|</div><div class="line">* | 8f87edefb3 Windows worker connection steps <span class="keyword">for</span> Azure</div><div class="line">* | a24372ddde Update Rethink DB <span class="built_in">command</span></div><div class="line">* | 738d87c1bf Correct sync_schedule <span class="keyword">in</span> ucp-description-file.md</div><div class="line">* | d0cab2a0d5 Use valid CPU limits</div><div class="line">...</div></pre></td></tr></table></figure></p>
<h3 id="Git-Merge"><a href="#Git-Merge" class="headerlink" title="Git Merge"></a>Git Merge</h3><p>比较复杂，另开一文</p>
<h3 id="Git-email"><a href="#Git-email" class="headerlink" title="Git email"></a>Git email</h3><p>Git 可以在命令行中生成 diff 的报告，以 Emai 的形式发送报告，比如我们现在处在 dev 分支下，然后与 master 进行比较：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">$ git branch</div><div class="line">dev</div><div class="line">$ git format-patch -M origin/master</div><div class="line">0001-add.patch</div><div class="line">0002-add-1.patch</div><div class="line">0003-add-2.patch</div><div class="line">0004-add-3.patch</div></pre></td></tr></table></figure></p>
<p>执行 format-patch 后会生成每个 commit 修改过的内容并写入文件内，然后配置 ~/.gitconfig 的配置，加入 IAMP 的配置如下：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[imap]</div><div class="line">        folder = <span class="string">"[126]/Drafts"</span></div><div class="line">        host = imap://imap.163.com</div><div class="line">        user = xxx@63.com</div><div class="line">        pass = xx</div><div class="line">        port = 993</div><div class="line">        sslverify = <span class="literal">false</span></div></pre></td></tr></table></figure></p>
<p>配置完成后执行，发送邮件：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ cat *.patch | git imap-send</div><div class="line">sending 4 messages</div><div class="line">   0% (0/4) <span class="keyword">done</span></div></pre></td></tr></table></figure></p>
<p>还可以使用 SMTP 方式，首先配置 ~/.gitconfig ：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[sendemail]</div><div class="line">        smtpencryption = tls</div><div class="line">        smtpserver = smtp.163.com</div><div class="line">        smtpuser = xxx@163.com</div><div class="line">        smtppass = xxx</div><div class="line">        smtpserverport = 465</div></pre></td></tr></table></figure></p>
<p>执行发送邮件：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line">$ git send-email *.patch</div><div class="line">0001-add.patch</div><div class="line">0002-add-1.patch</div><div class="line">0003-add-2.patch</div><div class="line">0004-add-3.patch</div><div class="line">To whom should the emails be sent (<span class="keyword">if</span> anyone)? 383821949@qq.com</div><div class="line">Message-ID to be used as In-Reply-To <span class="keyword">for</span> the first email (<span class="keyword">if</span> any)? y</div><div class="line">Are you sure you want to use &lt;y&gt; [y/N]? y</div><div class="line">(mbox) Adding cc: xxx &lt;xxx@163.com&gt; from line <span class="string">'From: xxx &lt;xxx@163.com&gt;'</span></div><div class="line">From: xxx &lt;xxx1@163.com&gt;</div><div class="line">To: 383821949@qq.com</div><div class="line">Cc:  &lt;xxx1@163.com&gt;</div><div class="line">Subject: [PATCH 1/4] add *</div><div class="line">Date: Wed, 22 Nov 2017 09:39:09 +0800</div><div class="line">Message-Id: &lt;20171122013912.9800-1-xxx1@163.com&gt;</div><div class="line">X-Mailer: git-send-email 2.13.6 (Apple Git-96)</div><div class="line">In-Reply-To: &lt;y&gt;</div><div class="line">References: &lt;y&gt;</div><div class="line">    The Cc list above has been expanded by additional</div><div class="line">    addresses found <span class="keyword">in</span> the patch commit message. By default</div><div class="line">    send-email prompts before sending whenever this occurs.</div><div class="line">    This behavior is controlled by the sendemail.confirm</div><div class="line">    configuration setting.</div><div class="line">    For additional information, run <span class="string">'git send-email --help'</span>.</div><div class="line">    To retain the current behavior, but squelch this message,</div><div class="line">    run <span class="string">'git config --global sendemail.confirm auto'</span>.</div><div class="line">Send this email? ([y]es|[n]o|[q]uit|[a]ll): y</div></pre></td></tr></table></figure></p>

        </div>
        <div id="post-footer">
            <div class="avatar" >
                <img src="/img/author.jpg" alt="avatar"/>
                <!-- 
                <a href="javascript:void(0)" class="high-song">high起来 &#128541;</a>
                 -->
                
                <a href="http://backup-miabon.oss-cn-hongkong.aliyuncs.com/img/alipay.jpg" target="_blank" class="donate fa">打赏小弟 &#128536;</a>
                
            </div>
            <ul class="author-profile-section">
                <li>
                  
                  作者:
                  
                    
                    <a href="/about.html">MIAbon</a>
                </li>
                
                <li>发表日期: <span>2017-11-29  00:00:00</span></li>
                
                <li>最后编辑日期: <span>2017-12-19  20:56:02</span></li>
                
                <li class="post-category">
                    文章分类:
                    
                    <a href="/categories/admin/">admin</a>
                    
                </li>
                <li class="post-tags">
                    文章标签:
                    
                    <a href="/tags/linux/">linux</a>
                    
                </li>
                
                <li> 版权声明: <a href="https://creativecommons.org/licenses/by-nc-nd/3.0/" target="_blank">
知识共享署名-非商业性使用-禁止演绎 3.0 未本地化版本许可协议（CC BY-NC-ND 3.0）
</a></li>
                
            </ul>
            <div id="donate-wrap">
                
                
                
                <img src="http://www.geasslinks.com/img/alipay.jpg" alt="支付宝付款" class="donate-img">
                
                
            </div>
        </div>
    </article>
    <div class="article-nav">
        
        <a href="/2017/11/29/Linux升级内核开启BBR的好处/" class="pre-post fa fa-caret-left">Linux升级内核开启BBR的好处</a>
        
        
        <a href="/2017/11/20/ELK简介/" class="next-post fa">ELK简介</a>
        
    </div>
    
    <div id="comments">
        

<script>
  gitment.render(document.getElementById("comments"));
</script>



    </div>
    
</div>


    </div>
    <footer id="footer">
    
    <div class="social">
        
        <a href="https://www.example1.com" class="fa fa-free-code-camp" target="_blank" title="freecodecamp"></a>
        
        <a href="https://github.com/werewolf2101" class="fa fa-github" target="_blank" title="Follow me~"></a>
        
        <a href="mailto:werewolf2101@gmail.com" class="fa fa-email" target="_blank" title="Email"></a>
        
    </div>
    
    <div>
        
        <a href="/" class="copyright-links">MIAbon</a>&copy;2015 - 2018.All Rights
        Reserved.
    </div>
    <p>Powered by <a href="https://hexo.io" class="copyright-links" target="_blank">Hexo</a> | Theme by <a
                href="https://github.com/GeekaholicLin" class="copyright-links" target="_blank">GeekaholicLin</a>
    </p>
    
    
    <p>
        <span id="busuanzi_container_site_uv" class="fa fa-bar-chart">
        欢迎第<span id="busuanzi_value_site_uv"><i class="fa fa-spinner fa-spin"></i></span>位小伙伴~
        </span>
    </p>
    
</footer>

</div>
    <ul id="tools">
    <li class="totop-btn fa fa-angle-up"></li>
    <li class="exchange-btn fa fa-exchange"></li>
  
    <li class="toc-btn fa fa-list-ul"></li>
    
    

    
</ul>
<p id="process"></p>
<div id="search-overlay">
    <div class="search-area-wrap">
        <div id="search-area">
            <div class="input-wrap focus">
                <i class="fa fa-search" aria-hidden="true"></i>
                <input id="search-input" autofocus autocomplete="off" type="text"
                       placeholder="search this website..."/>
            </div>
            <ul id="search-result">
                <li class="load-first"><i class="fa fa-spinner fa-pulse"></i></li>
            </ul>
        </div>
    </div>
</div>

    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Git的首次配置"><span class="toc-number">1.</span> <span class="toc-text">Git的首次配置</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#用户身份"><span class="toc-number">1.1.</span> <span class="toc-text">用户身份</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#检查个人设置"><span class="toc-number">1.2.</span> <span class="toc-text">检查个人设置</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#获取Git仓库"><span class="toc-number">2.</span> <span class="toc-text">获取Git仓库</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#在现有目录中初始化-Git-仓库"><span class="toc-number">2.1.</span> <span class="toc-text">在现有目录中初始化 Git 仓库</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-Add"><span class="toc-number">2.1.1.</span> <span class="toc-text">Git Add</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-Clone"><span class="toc-number">2.1.2.</span> <span class="toc-text">Git Clone</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#HTTP-Clone"><span class="toc-number">2.1.2.1.</span> <span class="toc-text">HTTP Clone</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#SSH-Clone"><span class="toc-number">2.1.2.2.</span> <span class="toc-text">SSH Clone</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-ignore"><span class="toc-number">2.1.3.</span> <span class="toc-text">Git ignore</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#ignore-忽略同步内容"><span class="toc-number">2.1.3.1.</span> <span class="toc-text">ignore 忽略同步内容</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-Remote"><span class="toc-number">2.1.4.</span> <span class="toc-text">Git Remote</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#远程仓库的使用"><span class="toc-number">2.1.4.1.</span> <span class="toc-text">远程仓库的使用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#显示远程仓库"><span class="toc-number">2.1.4.2.</span> <span class="toc-text">显示远程仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#添加远程仓库"><span class="toc-number">2.1.4.3.</span> <span class="toc-text">添加远程仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#从远程仓库获取和拉去数据"><span class="toc-number">2.1.4.4.</span> <span class="toc-text">从远程仓库获取和拉去数据</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#将数据推送到远程仓库"><span class="toc-number">2.1.4.5.</span> <span class="toc-text">将数据推送到远程仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#检查远程仓库"><span class="toc-number">2.1.4.6.</span> <span class="toc-text">检查远程仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#删除和重命名远程仓库"><span class="toc-number">2.1.4.7.</span> <span class="toc-text">删除和重命名远程仓库</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-commit"><span class="toc-number">2.1.5.</span> <span class="toc-text">Git commit</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-push"><span class="toc-number">2.1.6.</span> <span class="toc-text">Git push</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-Pull"><span class="toc-number">2.1.7.</span> <span class="toc-text">Git Pull</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Pull-冲突问题"><span class="toc-number">2.1.7.1.</span> <span class="toc-text">Pull 冲突问题</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Pull-完全覆盖"><span class="toc-number">2.1.7.2.</span> <span class="toc-text">Pull 完全覆盖</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-Stash"><span class="toc-number">2.1.8.</span> <span class="toc-text">Git Stash</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#储藏工作成果"><span class="toc-number">2.1.8.1.</span> <span class="toc-text">储藏工作成果</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#使用储存内容"><span class="toc-number">2.1.8.2.</span> <span class="toc-text">使用储存内容</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-Clean"><span class="toc-number">2.1.9.</span> <span class="toc-text">Git Clean</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Git-清理工作目录"><span class="toc-number">2.1.9.1.</span> <span class="toc-text">Git 清理工作目录</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-Grep"><span class="toc-number">2.1.10.</span> <span class="toc-text">Git Grep</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Git搜索"><span class="toc-number">2.1.10.1.</span> <span class="toc-text">Git搜索</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#Git-Grep-1"><span class="toc-number">2.1.10.1.1.</span> <span class="toc-text">Git Grep</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-Log"><span class="toc-number">2.1.11.</span> <span class="toc-text">Git Log</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#搜索特定作者的提交。-可以是字符串或正则表达式。"><span class="toc-number">2.1.11.1.</span> <span class="toc-text">搜索特定作者的提交。 可以是字符串或正则表达式。</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#搜索提交信息匹配特定-的提交。-可以是字符串或正则表达式"><span class="toc-number">2.1.11.2.</span> <span class="toc-text">搜索提交信息匹配特定  的提交。 可以是字符串或正则表达式</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#显示代表每个提交的一堆信息。显示每个提交全部的差异（diff），这也是项目历史中最详细的视图。"><span class="toc-number">2.1.11.3.</span> <span class="toc-text">显示代表每个提交的一堆信息。显示每个提交全部的差异（diff），这也是项目历史中最详细的视图。</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#查看当前所在分支的-HEAD"><span class="toc-number">2.1.11.4.</span> <span class="toc-text">查看当前所在分支的 HEAD</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-Merge"><span class="toc-number">2.1.12.</span> <span class="toc-text">Git Merge</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-email"><span class="toc-number">2.1.13.</span> <span class="toc-text">Git email</span></a></li></ol></li></ol></li></ol>


    <script src="/js/highsong.js"></script>



<script src="/js/search.js"></script>
<script type="text/javascript">
    //theme config datas
    var copyrightObj = {};
    copyrightObj.enable = 'true';
    copyrightObj.triggerCopyLength = '200';
    copyrightObj.appendText = '商业转载请联系作者获得授权,非商业转载请注明出处 © gasslinks.com';
    var leancloudObj = {};
    leancloudObj.enable = 'true';
    leancloudObj.className = 'blog';
    leancloudObj.limits = '5';
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?dfebe5842f5d4196471b84802392a4b2";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<script type="text/javascript">
    var search = {};
    var search_path = "search.xml";
    if (!search_path) {
        search_path = "search.xml";
    }
    search.path = "/" + search_path;
    search.func =  _ajax.init();
</script>
<script src="/js/app.js"></script>


</body>
</html>